//
//  HomePageDetailCollectionViewCell.m
//  miaopai
//
//  Created by Crow Zhang on 15/11/14.
//  Copyright © 2015年 Crow Zhang. All rights reserved.
//

#import "HomePageDetailCollectionViewCell.h"
#import "GetColor.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@interface HomePageDetailCollectionViewCell()

@property(nonatomic, retain)UIView *backView;

@property(nonatomic, retain)UIImageView *pic;

@property(nonatomic, retain)UILabel *label;

@end

@implementation HomePageDetailCollectionViewCell

- (void)dealloc
{
    [_backView release];
    [_pic release];
    [_label release];
    [_channel release];
    [_topic release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatView];
    }
    return self;
}

- (void)creatView
{
    self.backView = [[UIView alloc] init];
    _backView.backgroundColor = [UIColor whiteColor];
    _backView.layer.shadowOffset = CGSizeMake(0, 3);
    _backView.layer.shadowColor = [[UIColor grayColor] CGColor];
    _backView.layer.shadowOpacity = 0.8;
    [self addSubview:_backView];
    [_backView release];
    
    self.pic = [[UIImageView alloc] init];
    //_pic.backgroundColor = [UIColor yellowColor];
    [_backView addSubview:_pic];
    [_pic release];
    
    self.label = [[UILabel alloc] init];
    _label.numberOfLines = 0;
    _label.font = [UIFont systemFontOfSize:13];
    [_backView addSubview:_label];
    [_label release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _backView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    _pic.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.width);
   // _label.frame = CGRectMake(10, self.frame.size.width , self.frame.size.width - 20, self.frame.size.height - self.frame.size.width);
}

- (void)setChannel:(Channel *)channel
{
    if (_channel != channel) {
        [_channel release];
        _channel = [channel retain];
    }
    NSString *picStr = [NSString stringWithFormat:@"%@%@", _channel.pic.base, _channel.pic.m];
    [self.pic sd_setImageWithURL:[NSURL URLWithString:picStr] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    self.label.text = channel.ext.t;
    self.label.textAlignment = NSTextAlignmentLeft;
    self.label.backgroundColor = [UIColor whiteColor];
    self.label.textColor = [UIColor colorWithRed:0.5141 green:0.5141 blue:0.5141 alpha:1.0];
    _label.frame = CGRectMake(10, self.frame.size.width , self.frame.size.width - 20, self.frame.size.height - self.frame.size.width);
}

- (void)setTopic:(HomePageDetailTopic *)topic
{
    if (_topic != topic) {
        [_topic release];
        _topic = [topic retain];
    }
    [self.pic sd_setImageWithURL:[NSURL URLWithString:_topic.img] placeholderImage:nil];
    self.label.text = _topic.title;
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.textColor = [UIColor whiteColor];
    self.label.backgroundColor = [GetColor getColor:_topic.color];
    _label.frame = CGRectMake(0, self.frame.size.width - 30, self.frame.size.width, 30);
}

@end
